'use strict';

let debug = require('debug')('article');
let esDao = new require('./es/ArticleDao.js')();

let DaoDispatcher = function () {
};
module.exports = new DaoDispatcher();

let theProto = DaoDispatcher.prototype;

/**
 * 添加单个
 {
    "uid":"xxx",
    "articleId":"xxx",
    "nickName":"xxx",
    "articleContent":"xxx"
 }
 * @param inParams
 * @returns {*}
 */
theProto.addOne = function*(inParams) {
    let result = yield esDao.createSingle(inParams);
    return result;
};

theProto.addMany = function*(list) {
    let result = yield esDao.createMany(list);
    return result;
};

theProto.termFreq = function*(field, topNum) {
    let result = yield esDao.termFreq(field, topNum);
    return result;
};

theProto.qSearch = function*(q) {
    let result = yield esDao.qSearch(q);
    return result;
};

/**
 * get /api/v1/article/cscore?q=宝宝&add=1&sub=2&mul=3
 * @param json {q: q, add: add, sub: sub, mul: mul}
 * @returns {*}
 */
theProto.cScore = function*(json) {
    let result = yield esDao.cScore(json);
    return result;
};

/**
 * delete all doc then rebuild the mapping
 * @param q
 * @returns {*}
 */
theProto.reBuild = function*(q) {
    let result = yield esDao.reBuild(q);
    return result;
};
